<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="layuiadmin/plugins/dtree/dtree/dtree.css">
<link rel="stylesheet" href="layuiadmin/plugins/dtree/dtree/font/dtreefont.css">
  <style type="text/css">
	.layui-form .layui-form-item{
		width:90%;
	}
	</style>
</head>
<body style="margin-top: 10px">
<form class="layui-form" lay-filter="myform">
<input type="hidden" name="id">
<input type="hidden" name="state" value="1">
<input type="hidden" name="orgId" id="orgId" th:value="${session.MEORG.id}">
		<div class="layui-form-item">
		    <label class="layui-form-label">人员姓名</label>
		    <div class="layui-input-inline">
		      <input type="text" name="name" lay-verify="required|username" autocomplete="off" class="layui-input">
		    </div>
		    <label class="layui-form-label">登录账号</label>
		    <div class="layui-input-inline">
		      <input type="text" name="code" lay-verify="code" autocomplete="off" class="layui-input">
		    </div>
		    <label class="layui-form-label">部门</label>
		    <div class="layui-input-inline">
      			<ul id="nodeOrgId" name="nodeOrgId" class="dtree" data-id="0" ></ul>
    		</div>
	  	</div>
	  	<div class="layui-form-item">
	  		<label class="layui-form-label">手机号</label>
		    <div class="layui-input-inline">
		      <input type="text" name="mobileno" autocomplete="off" class="layui-input">
		    </div>
		    <label class="layui-form-label">员工工号</label>
		    <div class="layui-input-inline">
		      <input type="text" name="jobNumber" autocomplete="off" class="layui-input">
		    </div>
		    <label class="layui-form-label">性别</label>
		    <div class="layui-input-inline">
		      <select name="gender" id="gender" lay-filter='gender'></select>
		    </div>
	  	</div>
	  	<div class="layui-form-item">
	  		<label class="layui-form-label">简拼</label>
		    <div class="layui-input-inline">
		      <input type="text" name="initialLetter" autocomplete="off" readonly="readonly" placeholder="系统生成" class="layui-input">
		    </div>
		    <label class="layui-form-label">全拼</label>
		    <div class="layui-input-inline">
		      <input type="text" name="fullPinyin" autocomplete="off" readonly="readonly" placeholder="系统生成" class="layui-input">
		    </div>
		    <!--<label class="layui-form-label">员工类别</label>
		    <div class="layui-input-inline">
		      <select name="staffType" id="staffType"></select>
		    </div>-->
		    
	  	</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">角色</label>
    		<div class="layui-input-inline" style="width:410px!important">
      			<input id="roleCode" name="roleCode" type="hidden">
      			<input id="roleName" name="roleName" type="text" readonly="readonly" class="layui-input">
    		</div>
		    <label class="layui-form-label">OPENID</label>
    		<div class="layui-input-inline">
      			<input id="openId" name="openId" type="text" readonly="readonly" class="layui-input">
    		</div>
	  	</div>
	  	<div class="layui-form-item">
		    <label class="layui-form-label">登记人</label>
		    <div class="layui-input-inline">
       	 	   <input type="text" name="createUserName" id="createUserName" lay-filter="createUserName" th:value="${session.me.name}" readonly="readonly" class="layui-input">
       	 	   <input type="hidden" name="createUserId" id="createUserId" th:value="${session.me.id}">
		    </div>
		    <label class="layui-form-label">登记时间</label>
		    <div class="layui-input-inline">
       	 	   <input type="text" name="createTime" id="createTime" lay-filter="createTime" th:value="${currentTime}" readonly="readonly" class="layui-input">
		    </div>
	  	</div>
		<button id="submitBtn" class="layui-btn" style="display:none" lay-submit lay-filter="submitme">保存</button>
</form>
<script src="layuiadmin/plugins/xm-select/xm-select.js"></script>
 <script type="text/javascript" th:inline="javascript">
/*<![CDATA[*/
var id=/*[[${id}]]*/ 
var orgId=/*[[${orgId}]]*/ 
var myorgId=/*[[${session.MEORG.id}]]*/

/*]]>*/
</script>
<script th:inline="none">
layui.extend({ 
	dtree: '{/}layuiadmin/plugins/dtree/dtree/dtree'
});
layui.use(['element','table','dtree','form','upload','laydate'], function(){
    var form = layui.form,
    element = layui.element,
    laydate = layui.laydate,
    upload = layui.upload,
    dtree = layui.dtree;

    var entity = null;
    if(id){
    	entity = getEntityInfo(id,"user/getById");
    }
    var orgTree = dtree.renderSelect({
		  elem: "#nodeOrgId",
		  url: "org/getDTree",
		  checkbar: false ,
		  selectTips: "选择部门",
		  done:function(a,b,c){
			  if(id){
				  if(entity!=null&&entity.nodeOrgId){
					  dtree.dataInit("nodeOrgId",entity.nodeOrgId);
                      dtree.selectVal("nodeOrgId",entity.nodeOrgId);
				  }
			  }else{
				  if(orgId){
					  dtree.dataInit("nodeOrgId",orgId);
                      dtree.selectVal("nodeOrgId",orgId);
				  }
			  }
			  
		  }
	});
	createSelect("sex","gender",form);
	createSelect("staff-type","staffType",form);
	$("#roleName").on("click",function(){
		let url = 'rooter?url=system/role/select-role';
		if(id){
			url = url + "&userId="+id+"&roleCode="+$("#roleCode").val();
		}
		top.layer.open({
	    	type: 2,
	    	title:'选择角色',
	    	area:['1200px','700px'],
	    	content: url,
	    	btn:['确定','关闭'],
	    	yes:function(index,layero){
	    		var iframeWin = top.window[layero.find('iframe')[0]['name']];
	    	    var posts = iframeWin.getLeftCodes();
	    	    $("#roleCode").val(posts[0])
	    	    $("#roleName").val(posts[1])
	    	    top.layer.close(index)
	    	}
	    })    
	})
    function loadData(){
		var userEntity = getEntityInfo(id,"user/getById");
    	form.val('myform',userEntity);
    }
    if(id){
    	setTimeout(function(){
    		loadData();
    	},500)
    }else{
    	
    }
	form.on('submit(submitme)', function(data){
		var values = {};
		$(":input").each(function(i,v){
			if(v.name)
			values[v.name] = v.value;
		})
		values.nodeOrgId = values.nodeOrgId_select_nodeId;
		var url = 'user/save';
		$.ajax({
			url: url,
			data: JSON.stringify(values),
			type:'POST',
			dataType:'JSON',
			contentType:"application/json",
			success: function(res){
				if(res.code!=0){
					layer.msg(res.msg);
				}else{
					let win = getTabWin();
					win.loadGrid("user-table");
					layer.msg("保存成功");
					var index = top.layer.getFrameIndex(window.name); 
					top.layer.close(index); 
				}
			}
		})
		return false; 
	});
	form.verify({
		username: function(value, item){ //value：表单的值、item：表单的DOM对象
		    if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
		      return '用户名不能有特殊字符';
		    }
		    if(/(^\_)|(\__)|(\_+$)/.test(value)){
		      return '用户名首尾不能出现下划线\'_\'';
		    }
		    if(/^\d+\d+\d$/.test(value)){
		      return '用户名不能全为数字';
		    }
		 },
		 mobile: function(value, item){ 
		    if(!isMobileno(value)){
		      return '手机格式不正确';
		    }
		 }
	});  
});
</script>
</body>
</html>